package domain;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.MapKey;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.OrderBy;
import javax.persistence.Table;
@Table(name="t_item")
@Entity
public class Item {
	private String name;
	private String isDel = "1";
	private List<Topic> topics = new ArrayList<Topic>();
	private List<LookedUsers> user_look = new ArrayList<LookedUsers>();
	private Map<String,User> user_look_m2m = new HashMap<String,User>();
	private int item_id;//���г�id
	private double price;//���ÿ��
	private String classified;//���г�����
	private int num;//���г�����
	private String old_new;//�¾ɳ̶�
	private String color;//��ɫ
	private String  unit;//���»��ǰ���ȵ�
	private Date createDate;
	private String state;
	private User owner;
	private String sellOrBuy;
	
	private ItemImg ii;
	
	
	

	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	@OneToOne(cascade=CascadeType.ALL,fetch=FetchType.EAGER)
	@JoinColumn(name="owner_id")
	public User getOwner() {
		return owner;
	}
	public void setOwner(User owner) {
		this.owner = owner;
	}
	//	永远会加上多的那一方
	@OneToMany
	@JoinColumn(name="item_id")
	@OrderBy("post_time asc")
	public List<Topic> getTopics() {
		return topics;
	}
	@ManyToMany
	@MapKey(name="id")
	@JoinTable(name="item_look_users", joinColumns={@JoinColumn(name="item_id")}, inverseJoinColumns={@JoinColumn(name="user_id")})
	
	public Map<String, User> getUser_look_m2m() {
		return user_look_m2m;
	}
	public void setUser_look_m2m(Map<String, User> user_look_m2m) {
		this.user_look_m2m = user_look_m2m;
	}
	
	
	public void setTopics(List<Topic> topics) {
		this.topics = topics;
	}
//	@ManyToMany
//	@JoinTable(name="item_look_users", joinColumns={@JoinColumn(name="item_id")}, inverseJoinColumns={@JoinColumn(name="user_id")})
//	public List<User> getUser_look_m2m() {
//		return user_look_m2m;
//	}
//
//
//	public void setUser_look_m2m(List<User> user_look_m2m) {
//		this.user_look_m2m = user_look_m2m;
//	}


	@OneToOne(cascade=CascadeType.ALL,fetch=FetchType.EAGER)
	@JoinColumn(name="item_img_id")
	public ItemImg getIi() {
		return ii;
	}
	public void setUi(ItemImg ii) {
		this.ii = ii;
	}
	

	
	@Id
	@GeneratedValue
	public int getItem_id() {
		return item_id;
	}
	
//	永远会加上多的那一方
	@OneToMany(fetch = FetchType.EAGER)
	@JoinColumn(name="item_id")
	@OrderBy("look_time asc")
	public List<LookedUsers> getUser_look() {
		return user_look;
	}
	public void setUser_look(List<LookedUsers> user_look) {
		this.user_look = user_look;
	}
	public void setItem_id(int item_id) {
		this.item_id = item_id;
	}
	public double getPrice() {
		return price;
	}
	public void setPrice(double price) {
		this.price = price;
	}
	public String getClassified() {
		return classified;
	}
	public void setClassified(String classified) {
		this.classified = classified;
	}
	public int getNum() {
		return num;
	}
	public void setNum(int num) {
		this.num = num;
	}
	public String getOld_new() {
		return old_new;
	}
	public void setOld_new(String old_new) {
		this.old_new = old_new;
	}
	public String getColor() {
		return color;
	}
	public void setColor(String color) {
		this.color = color;
	}
	public String getUnit() {
		return unit;
	}
	public void setUnit(String unit) {
		this.unit = unit;
	}
	public Date getCreateDate() {
		return createDate;
	}
	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
	}
	public String getState() {
		return state;
	}
	public void setState(String state) {
		this.state = state;
	}

	public void setIi(ItemImg ii) {
		this.ii = ii;
	}
	public String getSellOrBuy() {
		return sellOrBuy;
	}
	public void setSellOrBuy(String sellOrBuy) {
		this.sellOrBuy = sellOrBuy;
	}
	@Column(columnDefinition="varchar(255) default '1'")
	public String getIsDel() {
		return isDel;
	}
	public void setIsDel(String isDel) {
		this.isDel = isDel;
	}
	
	
	
	
}
